import router from './router'
// import {
//   userOrderStore
// } from "@/store/index.js"
// let store = userOrderStore()
// let userOrder = localStorage.getItem('userOrder')
// let infoRegister = localStorage.getItem('infoRegister')

const whiteList = ['/register','/payResult','/goodOrder', '/goodHfOrder'];

router.beforeEach((to, from, next) => {
  // next()
  let token = localStorage.getItem('token')
  console.log(token, 'token', to)
  if (token) {
    /* has token*/
    if (to.path === '/register') {
      console.log(token, 't1111oken')
      next({ path: '/mine' })
    } else {
      console.log(token, '222222')
      next()
    }
  } else {
    // 没有token
    if (whiteList.indexOf(to.path) !== -1) {
      // 在免登录白名单，直接进入
      next()
    } else {
      next(`/register`) // 否则全部重定向到登录页
    }
  }
})

router.afterEach(() => {

})